// pages/order/order.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    items:{},
    dlr:{},
    pay:{},
    xiu:{},
    array:{},
    index:"6",
    price:{},
    quxiao:{},
    ordertime:{},
    realtime:{}
  },
  getdata: function (uid,dltype) {
    var _this = this
    wx.request({
      url: app.globalData.apiurl + 'api/index/order',
      method: "GET",
      data: {
        uid: uid,
        dltype:dltype
      },
      success: function (res) {
        console.log(res)
        _this.setData({
          items: res.data.order,
          array:res.data.progress
        })
        var con = _this.data.items
        var dlrr = _this.data.dlr
        var payy = _this.data.pay
        var xiuu = _this.data.xiu
        var pri  = _this.data.price
        var qx = _this.data.quxiao
        var ordertime = _this.data.ordertime
        var realtime = _this.data.realtime
        for (var i = 0; i < res.data.count; i++) {
          dlrr[i]="";
          payy[i]="none";
          xiuu[i]="none";
          pri[i]="";
          qx[i]="none";
          ordertime[i]="none";
          realtime[i]="none";
          if(con[i].dlrname==null){
            dlrr[i]="none"
          }
          console.log(con[i].progress)
          if(con[i].progress=="待付款"){
            payy[i]=""
          }
          if(con[i].progress=="已驳回"){
            xiuu[i]=""
          }
          if (con[i].progress == "待审核" || con[i].progress == "已驳回"){
            pri[i]="none"
          }
          if (con[i].progress == "待审核"||con[i].progress == "已驳回"){
            qx[i]=""
          }
          if (con[i].progress == "待取件"){
            ordertime[i]=""
          }
          if(con[i].progress == "已完成"){
            realtime[i]=""
          }
        }
        _this.setData({
          dlr:dlrr,
          pay:payy,
          xiu:xiuu,
          price:pri,
          quxiao:qx,
          ordertime:ordertime,
          realtime:realtime
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    this.getdata(app.globalData.userInfo.user_id);
  },
  //获取order信息
 



  //取消点击事件
  bindDel:function(e){
    var _this = this;
    var item = _this.data.items
    var ordernum = item[e.currentTarget.dataset.status].ordernum
    wx.showModal({
      title: '确认取消订单么？',
      icon:"none",
      success:function(e){
        if(e.confirm==true){
          wx.request({
            url: app.globalData.apiurl + 'api/index/order',
            method: "GET",
            data: {
              ordernum: ordernum
            },
            success: function (res) {
              _this.getdata(app.globalData.userInfo.user_id);
            }
          })
        }
      }
    })
  },
//详情事件
  bindDetail:function(e){
    var _this = this;
    var item = _this.data.items
    var ordernum = item[e.currentTarget.dataset.status].ordernum
    wx.navigateTo({
      url: '../orderdetail/orderdetail?ordernum='+ordernum,
    })
  },
//修改事件
  bindxiu:function(e){
    var _this =this;
    var item = _this.data.items
    var ordernum = item[e.currentTarget.dataset.status].ordernum
    wx.navigateTo({
      url: '../rebasefrom/rebasefrom?ordernum=' + ordernum,
    })
  },
//付款事件
  bindpay:function(e){
    var _this = this
    var item = _this.data.items
    var ordernum = item[e.currentTarget.dataset.status].ordernum
    wx.navigateTo({
      url: "/pages/pay/pay?ordernum="+ordernum,
    })
    /*
    wx.request({
      url: app.globalData.apiurl + 'api/index/orderpay',
      method: "GET",
      data: {
        ordernum:ordernum
      },
      success:function(){
        var getdata = _this.getdata(app.globalData.userInfo.user_id)
      }
    })*/
  },
  bindPickerChange:function(e){
    var _this = this
  if (e.detail.value == '0'||e.detail.value =='1'||e.detail.value =='2'||e.detail.value=='3'||e.detail.value=='4'||e.detail.value=='5'){
      var getdata = _this.getdata(app.globalData.userInfo.user_id, e.detail.value)
      _this.setData({
        index: e.detail.value
      })
    }
    if (e.detail.value == '6'){
      var getdata = _this.getdata(app.globalData.userInfo.user_id)
      _this.setData({
        index: e.detail.value
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.switchTab({
      url: '/pages/mine/mine',   //注意switchTab只能跳转到带有tab的页面，不能跳转到不带tab的页面
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})